package client.comm.baoding.ui

import android.content.Intent
import client.comm.commlib.utils.StoreUtil
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.BaseMiddleActivity
import client.comm.baoding.adapter.page.JifenFragmentPageAdapter
import client.comm.baoding.databinding.ActivityJifenBinding
import client.comm.baoding.ui.vm.JifenViewModel
import client.comm.commlib.toast.toast

/**
 * 积分记录
 */
class JifenActivity : BaseMiddleActivity<JifenViewModel, ActivityJifenBinding>() {

    val user: UserInfo? by lazy {
        StoreUtil.getBean<UserInfo>(this@JifenActivity)
    }
    val adapter: JifenFragmentPageAdapter by lazy {
        JifenFragmentPageAdapter(supportFragmentManager)
    }

    //所有，可转换，
    override fun getLayout(): Int {
        return R.layout.activity_jifen
    }

    override fun initViewModel(): JifenViewModel = createViewModel()

    override fun initView() {
        binding.event = this
        binding.vm = viewModel
        binding.viewPager.adapter = adapter
        binding.tabLayout.setupWithViewPager(binding.viewPager)
    }

    fun gqsfjl() {
        startActivity(Intent(this, GqsfjlActivity::class.java))
    }


    override fun observerUI() {
        viewModel.integralConvertCall.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    toast("转换成功")
                    viewModel.pageOne.value = 0
                    viewModel.holdOne()
                    viewModel.pageTwo.value = 0
                    viewModel.holdTwo()
                }
            }
        })
    }


}